/*
	Copyright 2009 Benjamin Vedder	vedder87@gmail.com
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

package com.google.code.retrobox.editor.dataCollections;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import com.google.code.retrobox.editor.tiles.Tile;
import com.google.code.retrobox.editor.tiles.TileSetPanel;


public class MapData implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	// Map data
	private List<Tile> tiles = new LinkedList<Tile>();
	private TileSet tileset;
	private TileSetPanel setp = null;
	
	private int 	mapWidth = 0,
					mapHeight = 0;
	
	public MapData(TileSet ts, char[] mapData, int w, int h) {
		tileset = ts;
		mapWidth = w;
		mapHeight = h;
		setData(mapData);
	}
	
	public MapData(TileSet ts, int w, int h) {
		tileset = ts;
		mapWidth = w;
		mapHeight = h;
		
		for (int i = 0;i < (w * h);i++) {
			Tile t = new Tile (null, tileset.getTile(Tile.DEFAULT_TILE));
			tiles.add(t);
		}
	}
	
	public void setTileSetPanel(TileSetPanel pan) {
		for (Tile element: tiles) {
			element.setTileSetPanel(pan);
		}
		setp = pan;
	}
	
	public TileSetPanel getTileSetPanel() {
		return setp;
	}
	
	public TileSet getTileSet() {
		return tileset;
	}
	
	public void setData(char[] mapArray) {
		for (char element: mapArray) {
			Tile t = new Tile (null, tileset.getTile(element));
			tiles.add(t);
		}
	}
	
	public List<Tile> getData () {
		return tiles;
	}
	
	public char[] getDataRaw() {
		char[] a = new char[tiles.size()];
		for (int i = 0;i < tiles.size();i++) {
			a[i] = (char)tiles.get(i).getTileData().index;
		}
		return a;
	}
	
	public int getMapWidth () {
		return mapWidth;
	}
	
	public int getMapHeight() {
		return mapHeight;
	}
}



